﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxHeadline;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.ASPxCallback;

public partial class NPS_app_Marketing_ViewSummary : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            loadForm();
            search();
        }
        else
        {
            bindit();
        }
        dgMarketing.GroupBy(dgMarketing.Columns["Marketing Name"]);
    }

    protected void bindit()
    {
       
         dgMarketing.DataSource = (List<Entities.NPSMarketingActivity>)Session["mvsData"];
         dgMarketing.DataBind();
    }

    protected void dgMarketing_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
    {
        if (e.Parameters.ToUpper().StartsWith("SELECT"))
        {
            HandleSelect(e.Parameters);
        }
        else if (e.Parameters.ToUpper().StartsWith("CHANGE"))
        {
            HandleRefresh();
        }
    }
    protected void cbkMarketing_Callback(object sender, CallbackEventArgs e)
    {

    }

    protected void HandleSelect(String sxParameter)
    {
      
    }
    
   
    protected void HandleRefresh()
    {
        dgMarketing.DataSource = null;
        dgMarketing.DataBind();
        dgMarketing.Selection.UnselectAll();
    }

    protected void search()
    {
        string name, type;
        DateTime start, end;
        start = txtStartDate.SelectedDate;
        end = txtEndDate.SelectedDate;
        name = ddlMarketingName.SelectedValue;
        type = ddlMarketingType.SelectedValue;
        Controller.NPSMarketingActivityController mac = new Controller.NPSMarketingActivityController();
        List<Entities.NPSMarketingActivity> marketing = mac.getNPSMarketingActivityList(name, type, start, end);
        Session["mvsData"] = marketing;
        dgMarketing.DataSource = marketing;
        dgMarketing.DataBind();
    }

    protected void loadForm()
    {
        //load Activity Name Item
        Controller.NPSMarketingNameController ANController = new Controller.NPSMarketingNameController();
        List<Entities.NPSMarketingName> namelist=new List<Entities.NPSMarketingName>();
        namelist.Add(new Entities.NPSMarketingName(){iID=0,sxTitle="- All -"});
        namelist.AddRange(ANController.NPSMarketingNameList);
        ddlMarketingName.Items.Clear();
        ddlMarketingName.DataSource = namelist;
        ddlMarketingName.DataBind();

        //Load Activity Type Item
        Controller.NPSMarketingTypeController ATController = new Controller.NPSMarketingTypeController();
        List<Entities.NPSMarketingType> typelist = new List<Entities.NPSMarketingType>();
        typelist.Add(new Entities.NPSMarketingType() { iID = 0, sxTitle = "- All -" });
        typelist.AddRange(ATController.NPSMarketingTypeList);
        ddlMarketingType.Items.Clear();
        ddlMarketingType.DataSource = typelist;
        ddlMarketingType.DataBind();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        search();
    }
}
